import sys
import argparse
import crux
import shell_executive as s_e
import error_messages as e_m
import precedent_values as pv


def after_received(material_folder, pattern_selected, output_video_path, immediately):
    obj_dictionary = crux.pivot(material_folder, pattern_selected, output_video_path)

    if any(value == e_m.not_found_file for value in obj_dictionary.values()):
        print("\n", e_m.not_found_file)
        sys.exit(0)
    elif any(value == e_m.not_found_directory for value in obj_dictionary.values()):
        print("\n", e_m.not_found_directory)
        sys.exit(0)
    elif immediately == pv.immediately_yes:
        command_line = obj_dictionary["executed_cmd"]
        print("\n", "command_line:", command_line)
        s_e.execute_command_line(command_line)
    else:
        command_line = obj_dictionary["executed_cmd"]
        print("\n", "command_line:", command_line)


def main():
    parser = argparse.ArgumentParser(description="Process some parameters.")

    parser.add_argument(
        "-p",
        type=int,
        choices=[0, 1],
        help="""
        Voice pattern (0 or 1, 0 represents: Silent, 1 represents: Sound).         
        If you want to learn more detail, please read README
        """,
    )
    parser.add_argument("-o", type=str, help="Output new file directory path")
    parser.add_argument("-f", type=str, help="Original material files directory path")
    parser.add_argument(
        "-i",
        type=int,
        help="Do you want to execute immediately? 0 represents: No, 1 represents: Yes",
    )

    args = parser.parse_args()

    if args.p is None or args.o is None or args.f is None or args.i is None:
        parser.print_help()
    elif args.p not in [0, 1]:
        parser.print_help()
        print("Error Input Pattern")
    elif args.i not in [0, 1]:
        parser.print_help()
        print("Error Input Immediately")
    else:
        print("Parameters received:", args)
        print("Parameters 0-p:", args.p)
        print("Parameters 1-o:", args.o)
        print("Parameters 2-f:", args.f)
        print("Parameters 3-i:", args.i)
        after_received(args.f, args.p, args.o, args.i)


if __name__ == "__main__":
    main()
